package com.zky.controller;

import com.zky.pojo.HeadLine;
import com.zky.pojo.PortalVo;
import com.zky.service.portalService;
import com.zky.util.JwtHelper;
import com.zky.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@CrossOrigin
public class portalController {
    private static final Logger log = LoggerFactory.getLogger(portalController.class);
    @Autowired
    private portalService service;
    @Autowired
    private JwtHelper jwtHelper;
    @GetMapping("/portal/findAllTypes")
    @ResponseBody
    public Result findAllPortalType()
    {
        Result allTypes = service.findAllTypes();
        return allTypes;
    }
    @PostMapping("/portal/findNewsPage")
    @ResponseBody
    public Result findNewPage(@RequestBody PortalVo portalVo)
    {
        Result newPage = service.findNewPage(portalVo);
        return newPage;
    }
    @PostMapping("/portal/showHeadlineDetail")
    @ResponseBody
    public Result showHeadlineDetail(@RequestParam Integer hid)
    {
        Result result = service.showHeadlineDetail(hid);
        return result;
    }
    @PostMapping("/headline/publish")
    @ResponseBody
    public Result publish(@RequestBody HeadLine headLine,@RequestHeader String token)
    {
        int userId = jwtHelper.getUserId(token).intValue();
        headLine.setPublisher(userId);
        Result publish = service.publish(headLine);
        return publish;
    }
    @PostMapping("headline/findHeadLineByHid")
    @ResponseBody
    public Result findHeadLineByHid(@RequestParam Integer hid)
    {
        Result headLineByHid = service.findHeadLineByHid(hid);
        return headLineByHid;
    }
    @PostMapping("headline/update")
    @ResponseBody
    public Result updateHeadline(@RequestBody HeadLine headLine)
    {
        Result result = service.updateHeadlineMessage(headLine);
        return result;
    }
    @PostMapping("headline/removeByHid")
    @ResponseBody
    public  Result removeByHid(@RequestParam Integer hid)
    {
        Result result = service.removeByHid(hid);
        return result;
    }


}
